/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.risk.controller;

import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.risk.bean.CorpBean;
import com.koron.risk.bean.KeyWork;
import com.koron.risk.bean.KeyWorkDetail;
import com.koron.risk.service.api.KeyWorkService;
import com.koron.risk.util.BusinessCode;
import com.koron.system.annotation.Log;
import com.koron.system.discrete.BusinessManipulation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.swan.bean.MessageBean;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Api(tags = "keyWork", description = "重点工作")
@RestController
@RequestMapping("/keyWork")
public class KeyWorkController {
    @Autowired
    private KeyWorkService keyWorkService;

    @ApiOperation(value = "列表查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "workName", value = "工作名称" , paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "corpCode", value = "水司code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "departmentCode", value = "部门code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页数" , paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数" , paramType = "query", dataType = "Integer")
    })
    @GetMapping("queryForList.htm")
    public MessageBean queryForList(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                                    @ApiIgnore String corpCode, @ApiIgnore String workName,
                                    @ApiIgnore String departmentCode, @ApiIgnore Integer page, @ApiIgnore Integer pageSize) {
        if (null == user) {
            MessageBean<CorpBean> msg = new MessageBean<>();
            msg.setCode(BusinessCode.MESSAGE_CODE_ACTION_EXCEPTION);
            msg.setDescription(BusinessCode.MESSAGE_DESCRIPTION_ACTION_EXCEPTION);
            return msg;
        }
        return keyWorkService.queryForList(user, corpCode, workName, departmentCode, page, pageSize);
    }

    @ApiOperation(value = "根据ID查询重点工作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "重点工作ID", required = true, paramType = "query", dataType = "String")
    })
    @GetMapping("queryById.htm")
    public MessageBean queryById(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore String id) {
        if (null == user) {
            MessageBean<CorpBean> msg = new MessageBean<>();
            msg.setCode(BusinessCode.MESSAGE_CODE_ACTION_EXCEPTION);
            msg.setDescription(BusinessCode.MESSAGE_DESCRIPTION_ACTION_EXCEPTION);
            return msg;
        }
        return keyWorkService.queryById(id);
    }

    @ApiOperation(value = "新增重点工作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "水司code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "corpName", value = "水司名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "workName", value = "任务名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "departmentCode", value = "部门code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "departmentName", value = "部门名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "personCode", value = "确认人", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "personName", value = "确认人名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "workList", value = "重点工作明细list", required = true, paramType = "query", dataType = "String"),
    })
    @PostMapping("insertKeyWork.htm")
    @Log(title = "新增重点工作", businessManipulation = BusinessManipulation.INSERT)
    public MessageBean insertKeyWork(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                                     @ApiIgnore KeyWork keyWork, @RequestBody List<KeyWorkDetail> workList) {
        if (null == user) {
            MessageBean<CorpBean> msg = new MessageBean<>();
            msg.setCode(BusinessCode.MESSAGE_CODE_ACTION_EXCEPTION);
            msg.setDescription(BusinessCode.MESSAGE_DESCRIPTION_ACTION_EXCEPTION);
            return msg;
        }
        return keyWorkService.insertKeyWork(user, keyWork, workList);
    }

    @ApiOperation(value = "修改重点工作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "重点工作ID", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "workName", value = "任务名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "departmentCode", value = "部门code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "departmentName", value = "部门名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "personCode", value = "确认人", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "personName", value = "确认人名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "workList", value = "重点工作明细list", required = true, paramType = "query", dataType = "String"),
    })
    @PostMapping("updateKeyWork.htm")
    @Log(title = "修改重点工作", businessManipulation = BusinessManipulation.UPDATE)
    public MessageBean updateKeyWork(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                                     @ApiIgnore KeyWork keyWork, @RequestBody List<KeyWorkDetail> workList) {
        if (null == user) {
            MessageBean<CorpBean> msg = new MessageBean<>();
            msg.setCode(BusinessCode.MESSAGE_CODE_ACTION_EXCEPTION);
            msg.setDescription(BusinessCode.MESSAGE_DESCRIPTION_ACTION_EXCEPTION);
            return msg;
        }
        return keyWorkService.updateKeyWork(user, keyWork, workList);
    }

    @ApiOperation(value = "确认重点工作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "重点工作ID", required = true, paramType = "query", dataType = "String")
    })
    @PostMapping("affirmKeyWork.htm")
    @Log(title = "确认重点工作", businessManipulation = BusinessManipulation.UPDATE)
    public MessageBean affirmKeyWork(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore String id) {
        if (null == user) {
            MessageBean<CorpBean> msg = new MessageBean<>();
            msg.setCode(BusinessCode.MESSAGE_CODE_ACTION_EXCEPTION);
            msg.setDescription(BusinessCode.MESSAGE_DESCRIPTION_ACTION_EXCEPTION);
            return msg;
        }
        return keyWorkService.affirmKeyWork(user, id);
    }
}
